package cn.uniquesoft.controller;

import cn.uniquesoft.page.DataGrid;
import cn.uniquesoft.service.IBankService;
import cn.uniquesoft.service.IConnectService;
import cn.uniquesoft.service.IVisitService;
import cn.uniquesoft.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

@Controller
@RequestMapping(value="/connectgather")
public class ConnectGatherController {
    @Autowired
    private IConnectService connectService;
    @Autowired
    private IBankService bankService;

    @RequestMapping(value = "/index")
    public String index() {
        return "connectgather/index";
    }

    @RequestMapping(value = "/pageQuery1")
    @ResponseBody
    public DataGrid pageQuery1() {
        DataGrid dg = new DataGrid();
        ConnectVO c = new ConnectVO();
        List<ConnectGatherVO> clist = new ArrayList<>();
        List<BankVO> blist = this.bankService.findAll(null);
        for(BankVO b : blist){
            ConnectGatherVO connectGatherVO = new ConnectGatherVO();
            connectGatherVO.setBackname(b.getCname());
            c.setIbank(b.getIid());
            c.setIscall(1);
            connectGatherVO.setDhhf(this.connectService.findAll(c).size());
            c.setIscall(0);
            c.setIsvisit(1);
            connectGatherVO.setSmzf(this.connectService.findAll(c).size());
            c.setIscall(0);
            c.setIsvisit(0);
            List<ConnectVO> l = this.connectService.findAll(c);
            connectGatherVO.setDcyx(l.size());
            int hzje = 0;
            for(ConnectVO c1 : l){
                    hzje+=Integer.parseInt(c1.getCmoney());
            }
            connectGatherVO.setHzje(hzje);
            clist.add(connectGatherVO);
        }
        int dhhfhz = 0;
        int smzfhz = 0;
        int dcyxhz = 0;
        int hzjehz = 0;
        for(ConnectGatherVO c2 : clist){
            dhhfhz+=c2.getDhhf();
            smzfhz+=c2.getSmzf();
            dcyxhz+=c2.getDcyx();
            hzjehz+=c2.getHzje();
        }
        ConnectGatherVO c3 = new ConnectGatherVO();
        c3.setHzje(hzjehz);
        c3.setSmzf(smzfhz);
        c3.setDcyx(dcyxhz);
        c3.setHzje(hzjehz);
        c3.setBackname("汇总");
        clist.add(c3);
        dg.setRows(clist);
        dg.setTotal((long)clist.size());
        return dg;
    }

}
